

#ifndef NODEEQUAL_H
#define	NODEEQUAL_H

#include <QtGui>
#include "Node.h"

class NodeEqual : public Node {

    Q_OBJECT

public:
    NodeEqual()
    : Node(QString("equal"), 2, QString("=")) {
        // add the layout
        QHBoxLayout* layout = new QHBoxLayout(this);
        layout->setSpacing(1);
        layout->setContentsMargins(1, 1, 1, 1);

        // add the label
        QLabel* lab = new QLabel();
        lab->setText(getNodeValue());
        layout->addWidget(lab);
    }

    std::vector<Node*> getEquals() const {
        Q_ASSERT_X(numChildren() == 2, "", "Expected two children.");
        Q_ASSERT_X(getLeftChild(), "", "Expected valid left child.");
        Q_ASSERT_X(getRightChild(), "", "Expected valid right child.");

        std::vector<Node*> v;
        if (getRightChild()->getNodeType() == "equal") {
            std::vector<Node*> v1 = getRightChild()->getEquals();
            v.insert(v.end(), v1.begin(), v1.end());
        } else {
            v.push_back(getRightChild());
        }

        if (getLeftChild()->getNodeType() == "equal") {
            std::vector<Node*> v1 = getLeftChild()->getEquals();
            v.insert(v.end(), v1.begin(), v1.end());
        } else {
            v.push_back(getLeftChild());
        }
        return v;
    }

    QString toCasString() const {
        Q_ASSERT_X(getLeftChild() != 0, "Node::toCasString",
                "Could not find left hand child node.");
        Q_ASSERT_X(getRightChild() != 0, "Node::toCasString",
                "Could not find right hand child node.");
        Q_ASSERT_X(numChildren() == 2, "Node::toCasString",
                "Expected two children.");
        QString str;
        if (getLeftChild()->getNodeType() == "empty") str.append("_");
        else str.append(getLeftChild()->toCasString());
        str.append(getNodeValue());
        if (getRightChild()->getNodeType() == "empty") str.append("_");
        else str.append(getRightChild()->toCasString());
        return str;
    }
};

#endif	/* NODEEQUAL_H */

